package com.ctcemti.mdm.project.quartz.controller;

import com.ctcemti.mdm.common.result.Result;
import com.ctcemti.mdm.common.result.ResultEnum;
import com.ctcemti.mdm.project.quartz.entity.SysJobLog;
import com.ctcemti.mdm.project.quartz.service.ISysJobLogService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * 调度日志操作处理
 * 
 * @author bxf
 */
@RestController
@RequestMapping("/system/jobLog")
public class SysJobLogController
{

    @Autowired
    private ISysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志对象
     */
    @ApiOperation(value = "查询定时任务调度日志对象")
    @PostMapping("/query")
    @ApiImplicitParam(name="entity",value = "定时任务调度日志实体类")
    public Result<SysJobLog> query(HttpServletRequest request, HttpServletResponse response , Long jobLogId)
    {
        SysJobLog jobLog = jobLogService.selectJobLogById(jobLogId);
        return new Result<SysJobLog>(ResultEnum.SUCCESS,jobLog);
    }

    /**
     * 查询定时任务调度日志列表
     */
    @ApiOperation(value = "查询定时任务调度日志列表")
    @PostMapping("/list")
    @ApiImplicitParam(name="entity",value = "定时任务调度日志实体类")
    public Result<PageInfo<SysJobLog>> queryList(HttpServletRequest request, HttpServletResponse response , SysJobLog jobLog)
    {
        PageInfo<SysJobLog> pageInfo = new PageInfo(jobLogService.selectJobLogList(jobLog));
        return new Result<PageInfo<SysJobLog>>(ResultEnum.SUCCESS,pageInfo);
    }

    /**
     * 删除定时任务调度日志
     */
    @ApiOperation(value = "删除定时任务调度日志")
    @PostMapping("delete")
    @ApiImplicitParams({@ApiImplicitParam(name="ids",value = "主键ids串")})
    public Result<SysJobLog> remove(HttpServletRequest request, HttpServletResponse response ,String ids)
    {
        jobLogService.deleteJobLogByIds(ids);
        return new Result<SysJobLog>(ResultEnum.SUCCESS,null);
    }

    /**
     * 删除定时任务调度日志
     */
    @ApiOperation(value = "清空定时任务调度日志")
    @PostMapping("deleteAll")
    @ApiImplicitParams({@ApiImplicitParam(name="ids",value = "主键ids串")})
    public Result<SysJobLog> deleteAll(HttpServletRequest request, HttpServletResponse response)
    {
        jobLogService.cleanJobLog();
        return new Result<SysJobLog>(ResultEnum.SUCCESS,null);
    }


}
